#include <catch2/catch.hpp>

#include <array>

#include "solution.hpp"

using namespace solution_061;

TEST_CASE("061_permutation_sequence", "[061]") {
    std::array n{ ListNode(0), ListNode(1), ListNode(2), ListNode(3), ListNode(4), ListNode(5) };
    for (size_t i = 0, j = 1; j < n.size(); ++i, ++j)
        n[i].next = &n[j];

    SECTION("example 1") {
        n[5].next = nullptr;
        auto head = Solution().rotateRight(&n[1], 2);
        std::vector<int> ans;
        while (head) {
            ans.push_back(head->val);
            head = head->next;
        }
        CHECK(ans == std::vector{4,5,1,2,3});
    }

    SECTION("example 2") {
        n[2].next = nullptr;
        auto head = Solution().rotateRight(&n[0], 4);
        std::vector<int> ans;
        while (head) {
            ans.push_back(head->val);
            head = head->next;
        }
        CHECK(ans == std::vector{2,0,1});
    }

    SECTION("example 3") {
        n[2].next = nullptr;
        auto head = Solution().rotateRight(&n[1], 1);
        std::vector<int> ans;
        while (head) {
            ans.push_back(head->val);
            head = head->next;
        }
        CHECK(ans == std::vector{2,1});
    }

    SECTION("example 4") {
        n[0].next = nullptr;
        CHECK(Solution().rotateRight(&n[0], 1) == &n[0]);
    }
}
